package cn.xianyang._04_tran;

import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionListener;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;

/**
 * 自定义的事务处理器
 */
public class TranListener implements TransactionListener {
    public LocalTransactionState executeLocalTransaction(Message msg, Object arg) {
        System.out.println("本地mysql数据库保存用户数据成功！！");
        System.out.println(arg.toString());
        return LocalTransactionState.COMMIT_MESSAGE;//本地事务执行成功，提交
    }


    public LocalTransactionState checkLocalTransaction(MessageExt msg) {
        System.out.println("检查本地mysql有没有保存用户成功！！");
        //根据数据库的查询结果，返回是否本地事务成功！！
        return LocalTransactionState.ROLLBACK_MESSAGE;
    }
}
